package com.review.sort;

public class SimpleSort {
    //简单选择排序{1,2,3,4,5,6,7,9,10}
    public void simpleSort(int[] array) {

        for (int i = 0; i < array.length - 1; i++) {
            int index = i;//下标
            int tmp = array[i];//对应元素值
            for (int j = i + 1; j < array.length; j++) {//每次循环挑出第i小的数
                if (array[j] < tmp) {
                    index = j;//下标
                    tmp = array[j];//对应元素值
                }
            }
            if (index != i) {
                array[index] = array[i];
                array[i] = tmp;
            }
        }

    }

    public static void main(String[] args) {
        int[] ints = {8, 6, 7, 5, 9, 4, 1, 10, 2, 3};
        new SimpleSort().simpleSort(ints);
        for (int anInt : ints) {
            System.out.print(anInt + ",");
        }
    }
}
